/*
 * MovieRoomsForm.java
 *
 * Created on 10 de Junho de 2007, 13:03
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.view;

import com.EntertainerMidlet;
import com.ValueObjects.Sala;
import com.ValueObjects.Sessao;
import com.sun.cldc.util.j2me.CalendarImpl;
import com.view.components.CanvasColor;
import com.view.components.CanvasListGroup;
import com.view.components.CanvasListItem;
import java.io.IOException;
import java.util.Calendar;
import java.util.Vector;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

/**
 *
 * @author $Leandro$
 */
public class MovieRoomsForm extends SearchResultMovieForm {
    
    private Vector sessao;
    
    /** Creates a new instance of MovieRoomsForm */
    public MovieRoomsForm(EntertainerMidlet midlet, Vector sessao) {
        super(midlet,null);
        this.sessao = sessao;
        initForm();
    }
    
    public void goBack() {
        midlet.display.setCurrent(midlet.moviesForm);
    }
    
    public void goAhead() {
        midlet.movieForm = new MovieForm(midlet,midlet.currentMovie);
        midlet.display.setCurrent(midlet.movieForm);        
    }
    
    protected void initForm() {
        try {
            this.backgroundImg = Image.createImage("/imgs/background.png");
            searchImg = Image.createImage("/imgs/search.png");
            imgTitle = Image.createImage("/imgs/search_title.png");
            imgLupa = Image.createImage("/imgs/lupa.png");
            
            // Load images. Use mGraphics to draw on the backbuffer.
            mBufferImage = Image.createImage(imgTitle.getWidth(), imgTitle.getHeight());
            mGraphics = mBufferImage.getGraphics();
            
            rawInt = new int[imgTitle.getWidth() * imgTitle.getHeight()];
            imgTitle.getRGB(rawInt, 0, imgTitle.getWidth(), 0, 0, imgTitle.getWidth(), imgTitle.getHeight());
            
            t = new Thread(this);
            t.start();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        
        resultList = new CanvasListGroup(null,0,imgTitle.getHeight(),true);
        resultList.width = getWidth();
        resultList.height = getHeight();
        
        if(sessao != null) {
            for(int i = 0; i < sessao.size(); i++) {
                CanvasListItem item = new CanvasListItem(null,"",0,
                        new CanvasColor(0x000000),new CanvasColor(0x000000));
                
                Sessao sVO = (Sessao) sessao.elementAt(i);
                Sala slVO = sVO.getSala();
                item.text = slVO.getNome_sala() + " : " + sVO.horario;
                item.align = Graphics.TOP|Graphics.HCENTER;
                item.id = sVO.getId_sessao();
                
                resultList.addItem(item);
            }
        }
    }
}
